package com.kgo.log.logtools.socket;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;


public class LogService {
    private static final Logger log = LoggerFactory.getLogger(LogService.class);
    public void doListen() {
        ServerSocket server;
        try {
            server = new ServerSocket(9991);
            while (true) {
                Socket client = server.accept();
                new Thread(new SSocket(client)).start();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    class SSocket implements Runnable {
        Socket client;

        public SSocket(Socket client) {
            this.client = client;
        }

        public void run() {
            DataInputStream input;
            DataOutputStream output;
            try {
                input = new DataInputStream(client.getInputStream());
                output = new DataOutputStream(client.getOutputStream());
                Thread.sleep(5000L);
                String data = input.readUTF();
                output.writeUTF("Recive1:  " + data);
                log.info("接口名称 access {}", data);
                data = input.readUTF();
                output.writeUTF("Recive2:  " + data);
                log.info("接收的数据 {}", data);
            } catch (IOException e) {
                e.printStackTrace();
            } catch (Exception e) {}
        }
    }
    public static void main(String[] args) {
        LogService manager = new LogService();
        manager.doListen();
    }


}
